package com.redoor.app.stake.basicdata.controller;

import com.redoor.app.stake.basicdata.model.BaseAssetOperationDetailLog;
import com.redoor.app.stake.basicdata.model.LogEnum;
import com.redoor.app.stake.basicdata.service.BaseAssetOperationDetailLogService;
import com.redoor.app.stake.basicdata.service.LogService;
import com.redoornetwork.framework.core.response.ResponseResult;
import com.redoornetwork.framework.core.response.ResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* Created by wangjunlei on 2018-03-03 19:26:43.
*/
@RestController
@RequestMapping("/base/asset/operation/detail/logs")
public class BaseAssetOperationDetailLogController {

    @Autowired
    private BaseAssetOperationDetailLogService baseAssetOperationDetailLogService;

    @Autowired
    private LogService hsfLogService;

    @PostMapping
    public ResponseResult add(@RequestBody BaseAssetOperationDetailLog baseAssetOperationTrajectory) {
        hsfLogService.addLogToRedis(baseAssetOperationTrajectory, LogEnum.ASSET_TRACE_DETAIL_LOG);
        return ResultGenerator.generatorSuccess();
    }

    @GetMapping
    public ResponseResult getOneSave() {
        List<BaseAssetOperationDetailLog> baseAssetOperationTrajectories = hsfLogService.getLogFromRedis(1, LogEnum.ASSET_TRACE_DETAIL_LOG);
        baseAssetOperationDetailLogService.saveAll(baseAssetOperationTrajectories);
        return ResultGenerator.generatorSuccess(baseAssetOperationTrajectories);
    }


    @PostMapping(value = "/list")
    public ResponseResult list(String traceuuid) {
        List list = baseAssetOperationDetailLogService.getTraceDetailList(traceuuid);
        return ResultGenerator.generatorSuccess(list);
    }
}
